﻿using System;
using System.Diagnostics;
using UnityEngine;
using EventHandler = Utilities.EventHandler;

namespace Resoure.Script.Utilities
{
    public class MyTimer
    {
        public float InitialTime; //初始时间
        public float CurrentTime; //当前时间

        public int Type; //类型
        public int ID; //id
        public bool isGolbal; //是否是全局计时器
        public MyTimer(float initialTime, int type, int id,bool isGolbal)
        {
            this.InitialTime = initialTime;
            this.CurrentTime = initialTime;
            this.Type = type;
            this.ID = id;
            this.isGolbal = isGolbal;

        }

        public void ResetTimer()
        {
            
            CurrentTime = InitialTime;
        }

        public void AddCurrentTime(float add)
        {
            CurrentTime += add;
        }

       

        public void UpdateMyTimer(float factor)
        {
            CurrentTime -= Time.deltaTime*factor;
            if (CurrentTime <= 0&&isGolbal)
            {
                EventHandler.CallTimerTimeOut(Type,ID);
            }
        }
        
        
        
    }
}